home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Utilities / TarChive / FullUserBack < prev    next >
Encoding:
Text File  |  1992-08-19  |  6.5 KB  |  175 lines

  1. #! /usr/local/bin/perl 
  2. #Copyright 1992    Sherwood Botsford
  3.  
  4. ####################################################################
  5. #                         Full User Back                           #
  6. #                        Sherwood Botsford                         #
  7. #                   sherwood@space.ualberta.ca                     #
  8. #                            CAUTION:                              #
  9. #              NO WARRANTY IS EXPRESSED OR IMPLIED.                #
  10. #              SUITABILITY FOR TASK NOT GUARANTEED.                #
  11. #                      USE AT YOUR OWN RISK.                       #
  12. ####################################################################
  13. #         Feel free to modify this script for local use.           #
  14. #          If you come up with something really clever,            #
  15. #              let me know. Ditto if you find a bug.               #
  16. #                                                                  #
  17. #       If you want to be kept up to date on new versions,         #
  18. #                      let me know that too.                       #
  19. ####################################################################
  20.  
  21.  
  22. ####################################################################
  23. #                                                                  #
  24. #               Define labels, strings, and so on.                 #
  25. #                                                                  #
  26. ####################################################################
  27. #    So that I can time the script, and see how/when it dies
  28. print `date`;
  29.  
  30. #    This library also does some setup.
  31. #   Worth looking at before you go on.  
  32. #    Located in  /usr/local/lib/perl
  33.  
  34. require("TapeLibrary.perl");
  35.  
  36. #    The tape library can do various kinds of backups.  The type of backup
  37. #    is recorded in the the log file created during the verify pass.
  38. #    See also UserBack for private user backups.
  39. #    Possible other values for this string would be System Backup, Private
  40. #    Backup. etc.
  41. #    A similar module could be used for incremental backups.  This would
  42. #    require modification of the the subroutines TarDir, or the creation
  43. #    of a new subroutine, as TarDir currently doesn't have provision for 
  44. #    making incremental backups.
  45.  
  46. $BackupType="Full User ";
  47.  
  48. #    Customize
  49. #    You may wish to change ypcat to cat (for local users only) or 
  50. #   nidump (NeXT)
  51. #
  52. #    You will certainly need to change the names of the hosts that serve
  53. #    user directories.
  54.  
  55. @userlist=split(' ',`(ypcat passwd | egrep "arafel|fenris" |awk -f: '\{print(\$1)\}' | sort )`);
  56.  
  57. &Say( @userlist);
  58. $ErrorCode=0;    #    Used for reporting back errors from subroutines.
  59.  
  60. #Uncomment next line for testing
  61. #(Of course you will provide your own list of small users)
  62. #@userlist=(barry, beth, cliff, guy, karen, greg, myriam );    
  63.  
  64.  
  65. ####################################################################
  66. #            TapeLibrary has already rewound the tape,             #
  67. #                and has set the ioctl and drive.                  #
  68. #               Now we will check the Volume label,                #
  69. #                       and clear the tape.                        #
  70. #        Log files with this tape's name are now worthless         #
  71. #                        So we toast them.                         #
  72. #                                                                  #
  73. ####################################################################
  74.  
  75. #    CheckVolumeLabel returns the error number if something is wrong 
  76. #    and the tapelabel if all is ok.  So $ErrorCode has to be checked. 
  77.  
  78.  
  79. $tapelabel = &CheckVolumeLabel;
  80. print "Tape is labeled: $tapelabel\n";
  81. if ($LabelErrorCode != 100){
  82.     &ErrorTranslate($LabelErrorCode);
  83.     &Quit(ErrorCode);
  84.     }
  85.  
  86. #
  87. #        We have now established that the tape is legitimate, and that
  88. #    root has appropriate permission to write on the tape.  Now
  89. #    to actualy do the job.  (Permission is required as the backup 
  90. #    script usually runs in the middle of the night.  If someone else
  91. #    left a tape in the drive it would get clobbered.)
  92. #
  93.  
  94.  
  95. print "Deleting log files refering to this tape \n";
  96.  
  97. #    Customize:
  98. #    Put in the file systems where user home directories live.
  99. #    NOTE:  The command below assumes that these directories 
  100. #    contain ONLY user home directories.  
  101.  
  102. foreach $UserFileSystem ("/u/arafel", "/u/fenris"){
  103.     system("rm -f $UserFileSystem/*/backups/$tapelabel*");
  104.     }
  105.  
  106. #    Script can be called with -V for a verify only pass.
  107. #     so skip making the tar files if thats the case.
  108.  
  109. if ($ARGV[0] eq "-V") {goto VERIFY;}
  110.  
  111. # At this point the tape is positioned at the end of the 
  112. # tape label.  We will write an Logical End of Tape mark to
  113. # overwrite tape.
  114.  
  115. &EraseRestOfTape;
  116.  
  117. #     =========================================================    #
  118. #          Create a tar file for each user on this disk.
  119. #     =========================================================    #
  120.  
  121.  
  122. #    Customize. 
  123. #    This program puts log files in a directory called 
  124. #    backups.  If it doesn't exist it is created, with 
  125. #    root being the owner. Read and execute are set so that 
  126. #    the user can read the directory and files in it but
  127. #    not fiddle with the stuff in it. 
  128.  
  129.  
  130. foreach $u ( @userlist )    {
  131.     $Label = $tapelabel."-".$DateString."-".$u;
  132.     $udir = (getpwnam($u))[7];
  133.     print "\n Writing $u\'s home directory $udir to tape.\n";
  134.     if ( ! -d "${udir}/backups" ) {
  135.         print "Creating backup log file directory for $u. \n";
  136.         mkdir($udir."/backups",655);
  137.         }
  138.     &TarDir( $udir);
  139.     }    # End Foreach
  140.  
  141.  
  142.  
  143. #     =========================================================    #
  144. #                Reposition tape and compare
  145. #     =========================================================    #
  146. &RewindTape;
  147. VERIFY:{
  148.     print "STARTING VERIFY PASS";
  149.     $tarnum = 0;
  150.     # Remember that VerifyDir updates tarnum.
  151.     # Remember that VerifyDir expects to fsf before doing the read
  152.     foreach $loop ( @userlist )    {
  153.         $udir = (getpwnam($loop))[7];
  154.         $tarlabel=$udir."/backups/".$tapelabel."-".$DateString."-".$loop;
  155.         print "\nUser directory: ",$udir, "\ntarlabel: ",$tarlabel,"\n";
  156.                 
  157.         &VerifyDir(${udir}."/backups",$udir);
  158.         }    # End Foreach
  159.     }    #End VERIFY
  160. print `date`;
  161. #    End Program
  162.   &Offline;
  163.  
  164.  
  165. # gnutar return errors.
  166. #define EX_SUCCESS      0               /* success! */
  167. #define EX_ARGSBAD      1               /* invalid args */
  168. #define EX_BADFILE      2               /* invalid filename */
  169. #define EX_BADARCH      3               /* bad archive */
  170. #define EX_SYSTEM       4               /* system gave unexpected error */
  171. #define EX_BADVOL       5               /* Special error code means
  172. #                                          Tape volume doesn't match the one
  173. #                                          specified on the command line */
  174.  
  175.